﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TimKen.BussLogic;
using TimKen.DataAccess;
using TimKen.DataEntity;
using System.Globalization;

namespace TimKen.Web.Admin
{
    public partial class Main : TimKen.App.AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Admin"] == null)
                Response.Redirect("/Admin/Login.aspx", true);

            if (Session["lan"] != null)
                SetLanguage(Session["lan"].ToString());
            if (!Page.IsPostBack)
            {
                BindProductInfo();
                BindOrderInfo();
                BindSystemInfo();
            }
        }


        protected void SetLanguage(string language)
        {
            HttpCookie cookie = new HttpCookie("Language");
            DateTime dt = DateTime.Now;//定义时间对象
            TimeSpan ts = new TimeSpan(0, 20, 0);
            cookie.Expires.Add(ts);
            cookie.Value = language;
            HttpContext.Current.Response.AppendCookie(cookie);
            CultureInfo culture = new CultureInfo(language);
            System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
            System.Threading.Thread.CurrentThread.CurrentCulture = culture;
        }
        private void BindProductInfo()
        {
            ProductManager pm = new ProductManager();
            this.lblProductCount.Text = pm.GetProductCountByCategoryID(0).ToString();
        }
        private void BindOrderInfo()
        {
            OrderManager om = new OrderManager();
            this.lblOrderCount.Text = om.GetList("1=1").Tables[0].Rows.Count.ToString();
        }
        private void BindSystemInfo()
        {
            lblServerOS.Text = Environment.OSVersion.ToString();  //服务器操作系统
            lblCpuSum.Text = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");// CPU个数：
            lblCpuType.Text = Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER");// CPU类型：

            lblMachineName.Text = Server.MachineName;// 服务器名
            lblServerName.Text = Request.ServerVariables["SERVER_NAME"];// 服务器域名
            lblServerPath.Text = Request.ServerVariables["APPL_PHYSICAL_PATH"];// 虚拟服务绝对路径
            lblServerNet.Text = ".NET CLR " + Environment.Version.ToString(); // DotNET 版本
            lblServerArea.Text = (DateTime.Now - DateTime.UtcNow).TotalHours > 0 ? "+" + (DateTime.Now - DateTime.UtcNow).TotalHours.ToString() : (DateTime.Now - DateTime.UtcNow).TotalHours.ToString();// 服务器时区
            lblServerTimeOut.Text = Server.ScriptTimeout.ToString(); // 脚本超时时间
            lblServerStart.Text = ((Double)System.Environment.TickCount / 3600000).ToString("N2");// 开机运行时长
            // AspNet CPU时间
            lblServerSessions.Text = Session.Contents.Count.ToString();// Session总数
            lblServerApp.Text = Application.Contents.Count.ToString(); // Application总数
            lblServerCache.Text = Cache.Count.ToString(); //应用程序缓存总数

        }
    }
}
